<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /*
    创建函数，生成当前时间字符串，
    2021-10-19 10：17：20
    作为函数的返回值返回
    */

   function identify(num){
       return num<10?"0"+num:num;
   }
   
   function creatTime(){
       var now = new Date();
       var year = now.getFullYear();
       var month = now.getMonth()+1;
       var day = now.getDate();
       var hour = now.getHours();
       var minute = now.getMinutes();
       var second = now.getSeconds();

       month = identify(month);
       day = identify(day);
       hour = identify(hour);
       minute = identify(minute);
       second = identify(second);

       var result = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
       return result;
   }

   document.write(creatTime()+"</br>");
   document.write((new Date).toLocaleString());
</script>
</html>
